#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int x=0,f=1;char c;
    do c=getchar();while(!isdigit(c)&&c!='-');
    if(c=='-') f=-1,c=getchar();
    while(isdigit(c)) x=x*10+c-'0',c=getchar();
    return x*f;
}
const int N = 1e5+10;
const int M = 1e6+10;
struct car{
    int d,v,a,x;
}a[N];
int n,m,l,v,ans1,ans2;
int p[M],fr[M],bc[M],vis[M],ab[N],frr[M],bcc[M],viss[M];
int calc(int x){
    int tot=0;
    for(int i=0;i<m;i++)
        if(!((x>>i)&1)) tot++;
    return tot;
}
void work1(){
    int tot=1;
    for(int i=1;i<m;i++)
        tot<<=1;
    for(int q=tot-1;q>=0;q--){
        memset(frr,0,sizeof(frr));
        memset(bcc,0,sizeof(bcc));
        bool f=1;
        int x=calc(q);
        if(calc(q)<ans2) continue;
        for(int k=1;k<=l;k++)
            viss[k]=vis[k];
        for(int j=0;j<m;j++)
            if(!((q>>j)&1))
                viss[p[m-j]]=0;
        for(int i=1;i<=l;i++){
            frr[i]=frr[i-1];
            if(viss[i]) fr[i]++;
        }
        for(int i=l;i>=1;i--){
            bcc[i]=bcc[i+1];
            if(viss[i]) bcc[i]++;
        }
        for(int i=1;i<=n;i++){
            if(!ab[i]) continue;
            if(a[i].a>=0 && a[i].x!=l+1 && bcc[a[i].x]>0) continue;
            if(a[i].a<0 && a[i].x!=l+1 && frr[a[i].x]-frr[max(a[i].d-1,0)]>0) continue;
            f=0;break;
        }
        // cout<<x<<endl;
        if(f) ans2=x;
    }
    printf("%d\n",ans2);
}
void work2(){
    for(int i=1;i<=n;i++){
        if(ab[i]){
            printf("%d\n",m-1);
            return ;
        }
    }
    printf("%d\n",m);
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T=read();
    while(T--){
        //clear!!!!!!
        bool f=1;
        memset(a,0,sizeof(a));
        memset(vis,0,sizeof(vis));
        memset(fr,0,sizeof(fr));
        memset(bc,0,sizeof(bc));
        memset(ab,0,sizeof(ab));
        n=read(),m=read(),l=read(),v=read(),ans1=0,ans2=0;
        for(int i=1;i<=n;i++){
            a[i].d=read(),a[i].v=read(),a[i].a=read();
            if(a[i].a==0 && a[i].v<=v) a[i].x=l+1;
            else if(a[i].a==0 && a[i].v>v) a[i].x=a[i].d;
            else if(a[i].a>0 && ((long long)(a[i].v*a[i].v+2*a[i].a*(l-a[i].d)))<=v*v) a[i].x=l+1;
            else if(a[i].a>0 && a[i].v>v) a[i].x=a[i].d;
            else if(a[i].a>0) a[i].x=min(ceil((double)(-a[i].v*a[i].v+v*v)*1.0/2/a[i].a)+double(a[i].d),double(l*1.0));
            else if(a[i].a<0 && a[i].v<=v) a[i].x=l+1;
            else a[i].x=min(floor(double((v*v-a[i].v*a[i].v))*1.0/2/a[i].a)+a[i].d,double(l*1.0));
            if(a[i].a<0) f=0;
        }
        for(int i=1;i<=m;i++)
            p[i]=read(),vis[p[i]]=1;
        for(int i=1;i<=l;i++){
            fr[i]=fr[i-1];
            if(vis[i]) fr[i]++;
        }
        for(int i=l;i>=1;i--){
            bc[i]=bc[i+1];
            if(vis[i]) bc[i]++;
        }
        for(int i=1;i<=n;i++){
            if(a[i].a>=0 && a[i].x!=l+1 && bc[a[i].x]>0) ans1++,ab[i]=1;
            if(a[i].a<0 && a[i].x!=l+1 && fr[a[i].x]-fr[max(a[i].d-1,0)]>0) ans1++,ab[i]=1; 
            // cout<<i<<' '<<a[i].x<<endl;
        }
        // for(int i=1;i<=l;i++)
        //     printf("%d ",fr[i]);
        // putchar(10);
        // for(int i=1;i<=l;i++)
        //     printf("%d ",bc[i]);
        // putchar(10);
        printf("%d ",ans1);
        if(f) work2();
        else work1();
    }
    return 0;
}